package com.yun.algorithmproblem.leetcode;

public class Leetcode2239 {

    public int findClosestNumber(int[] nums) {
        int ans=nums[0];
        int dis=Math.abs(nums[0]);
        for (int num : nums) {
            if(Math.abs(num)<dis){
                ans=num;
                dis=Math.abs(num);
            }else if(Math.abs(num)==dis){
                ans=Math.max(ans,num);
            }
        }
        return ans;
    }
}
